package demo02_通过配置文件来编写;

import demo01_JDBC入门.User;
import utils.C3P0Utils;
import utils.JBDCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class test_测试工具类 {
    public static void main(String[] args) throws Exception{
        //获得连接池
        Connection connection = C3P0Utils.getConnection();
        //预编译sql语句,得到预编译对象
        String sql="select *from user where id=?";
        PreparedStatement ps = connection.prepareStatement(sql);
        //设置参数
        ps.setInt(1,2);
        //执行sql语句,处理结果
        ResultSet resultSet = ps.executeQuery();
        //定义一个变量
        User user=null;
        while (resultSet.next()){
            //取值
            int id = resultSet.getInt("id");
            String username = resultSet.getString("username");
            String password = resultSet.getString("password");
            String nickname = resultSet.getString("nickname");
            //封装
            user=new User(id,username,password,nickname);



        }
        //释放资源
        C3P0Utils.release(resultSet,ps,connection);
        System.out.println(user);
    }
}
